import java.util.Scanner;

public class Practice1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        while(k-- > 0){
            int n = sc.nextInt();
            char[] ss = new char[n];
            for (int i = 0; i < n; i++) {
                ss[i] = sc.next().charAt(0);
            }
            System.out.println(equal(ss, n));
        }
    }

    private static boolean equal(char[] ss, int n) {
        if(n % 2 == 0){
            int left = n / 2 - 1;
            int right = n / 2;
            while(left >= 0 && right < n && ss[left] == ss[right]){
                left++;
                right++;
            }
            if(right == n){
                return true;
            }
            return false;
        }else{
            int left = n / 2 - 1;
            int right = n / 2 + 1;
            while(left >= 0 && right < n && ss[left] == ss[right]){
                left++;
                right++;
            }
            if(right == n){
                return true;
            }
            return false;
        }
    }
}
